package com.example.mweather.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mweather.R;
import com.example.mweather.beans.HourlyItemBean;
import com.example.mweather.utils.WeatherUtil;

import java.util.List;

public class HourlyAdapter extends RecyclerView.Adapter<HourlyAdapter.RVHolder> {

    private List<HourlyItemBean> datas;

    public HourlyAdapter(List<HourlyItemBean> datas) {
        this.datas = datas;
    }

    @NonNull
    @Override
    public HourlyAdapter.RVHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_hourly, parent, false);
        return new RVHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HourlyAdapter.RVHolder holder, int position) {
        holder.tvTime.setText(datas.get(position).getTime());
        holder.ivSkycon.setImageResource(WeatherUtil.genIconBySkycon(datas.get(position).getSkycon()));
        holder.tvTemp.setText(datas.get(position).getTemp());
    }


    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class RVHolder extends RecyclerView.ViewHolder {
        private TextView tvTime;
        private ImageView ivSkycon;
        private TextView tvTemp;

        public RVHolder(@NonNull View itemView) {
            super(itemView);
            tvTime = itemView.findViewById(R.id.tvTime);
            ivSkycon = itemView.findViewById(R.id.ivSkycon);
            tvTemp = itemView.findViewById(R.id.tvTemp);
        }
    }
}
